﻿using System;
using System.Collections.Generic;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Soundteller.Common.Tests;
using Soundteller.Visual.Model;

namespace Soundteller.Visual.Tests.Unit.Services.DrawerSpecifications
{
    [TestClass]
    public class WhenDrawGivenGraphicIsNull : WhenDrawTestBase
    {
        protected override GraphicBase Graphic
        {
            get { return null; }
        }

        protected override void Act()
        {
            ExpectException(() => base.Act());
        }

        [TestMethod]
        public void ThenAnArgumentNullExceptionShouldBeThrown()
        {
            Exception.VerifyArgumentNullException("graphic");
        }
    }

    [TestClass]
    public class WhenDrawGivenNameIsNull : WhenDrawTestBase
    {
        protected override GraphicBase Graphic
        {
            get { return new GeneratedGraphic { Name = null }; }
        }

        protected override void Act()
        {
            ExpectException(() => base.Act());
        }

        [TestMethod]
        public void ThenAnArgumentNullExceptionShouldBeThrown()
        {
            Exception.VerifyArgumentException("graphic");
        }
    }

    [TestClass]
    public class WhenDrawGivenValidGraphic : WhenDrawTestBase
    {
        protected override GraphicBase Graphic
        {
            get { return new GeneratedGraphic { Name = "unit-test" }; }
        }

        [TestMethod]
        public void ThenGraphicShouldBeBuffered()
        {
            GraphicBufferRepository.Verify(r => r.Push(It.IsAny<GraphicBase>()), Times.Once());
        }
    }

    [TestClass]
    public class WhenDrawListGivenInnerGraphics : WhenDrawListTestBase
    {
        protected override IEnumerable<GraphicBase> Graphics
        {
            get 
            { 
                return new List<GraphicBase> 
                { 
                    new GeneratedGraphic 
                    { 
                        Name = "unit-test",
                        InnerGraphics = new List<GraphicBase>
                        {
                            new GeneratedGraphic{ Name = "inner-test" }
                        }
                    }
                }; 
            }
        }
        
        [TestMethod]
        public void ThenAllGraphicsShouldBeBuffered()
        {
            GraphicBufferRepository.Verify(r => r.Push(It.IsAny<GraphicBase>()), Times.Exactly(2));
        }
    }
}